* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file calculates the share of mergers in each industry for Appendix Table A.1.

* From Do File #P2
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\list_1992-2018_combined1865.dta", clear

* From Do File #P1
rename cvrnrA cvrnr
merge m:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename cvrnr cvrnrA
rename CVR_BRANCHE_DB07 indA
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename CVR_BRANCHE_DB07 indT
rename cvrnr cvrnrT

gen d_si=0 
replace d_si=1 if indA==indT
sum d_si

gen indA2 = floor(indA/10000)
gen indA4 = floor(indA/100)
gen indT2 = floor(indT/10000)
gen indT4 = floor(indT/100)

gen d_si2 = (indA2==indT2)
gen d_si4 = (indA4==indT4)

keep if aar>=1996 & aar<=2015
* Total number of deals
disp _N

* Share of horizontal mergers at 2-digit level
tab d_si2
* Share of horizontal mergers at 4-digit level
tab d_si4

* Distribution of industries
gen dig1 = "(A) Agriculture, forestry & fishing" if indA2>=1 & indA2<=4
replace dig1 = "(B) Mining & quarrying" if indA2>=5 & indA2<=9
replace dig1="(C) Manufacturing" if indA2>=10 & indA2<=33
replace dig1="(F) Construction" if indA2>=41 & indA2<=43
replace dig1="(G) Wholesale & retail trade" if indA2>=45 & indA2<=47
replace dig1="(H) Tranpsortation & storage" if indA2>=49 & indA2<=53
replace dig1="(I) Accomodation & food services" if indA2>=55 & indA2<=56
replace dig1="(J) Information & communication" if indA2>=58 & indA2<=63
replace dig1="(K) Finance & insurance" if indA2>=64 & indA2<=66
replace dig1="(L) Real estate" if indA2==68
replace dig1="(M) Prof., scientific & technical activities" if indA2>=69 & indA2<=75
replace dig1="(N) Administrative & support services" if indA2>=77 & indA2<=82

keep if d_si4==1

log using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A1.log", replace
tab dig1
log close